package edu.cdbi.view;

import tool.Tools;
import edu.cdbi.database.StudentManagement;
import edu.cdbi.model.instance.Student;


@SuppressWarnings("serial")
public class StudentPanel extends BasicPanel{
	
	public StudentPanel (){
		super();
		DTM.setColumnIdentifiers(new Object[]{"id", "name", "email"});
	}
	
	@Override
	protected void initialData() {
		addComponents.put("name", new BasicComponent());
		addComponents.put("email", new BasicComponent());
		
	}
	
	@Override
	protected void OKActionByAdd() {
		StudentManagement manager = new StudentManagement();
		if(manager.insert(addComponents.get("name").getText(), 
				addComponents.get("email").getText()) != null){
			Tools.showMSG("新增學生成功!");
		}else{
			Tools.showError("新增學生失敗!");
		}
		addComponents.get("name").setText("");
		addComponents.get("email").setText("");
	}

	@Override
	protected void OKActionByModify() {
	}

	@Override
	protected void addAction() {
		
	}

	@Override
	protected void cancelActionByAdd() {
	}

	@Override
	protected void cancelActionByModify() {
	}

	@Override
	protected void deleteAction() {
	}

	@Override
	protected void modifyAction() {
	}

	@Override
	protected void update() {
	}

	@Override
	protected void viewAction() {
		Tools.removeTableItems(DTM);
		StudentManagement manager = new StudentManagement();
		for(Student student : manager.getList()){
			DTM.addRow(new Object[]{student.getId(), student.getName(), student.getName()});
		}
	}
	
}
